package com.yima.baseproj.module.app.gentable.column;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yima.baseproj.module.app.gentable.column.model.AppGenTableColumnAddParamModel;
import com.yima.baseproj.module.app.gentable.column.model.AppGenTableColumnEditParamModel;
import com.yima.baseproj.module.app.gentable.column.model.AppGenTableColumnSearchModel;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
public class AppGenTableColumnService extends ServiceImpl<AppGenTableColumnMapper, AppGenTableColumnEntity> {

    public Page<Map> findByPage(Page page, AppGenTableColumnSearchModel searchVo) {
        return baseMapper.findBySearchVo(page,searchVo);
    }

    public List<Map> findByList(AppGenTableColumnSearchModel searchVo) {
        return baseMapper.findBySearchVo(searchVo);
    }

    /**
     * 添加 - 事务
     * @param paramModel
     */
    @Transactional(rollbackFor = Exception.class)
    public void add(AppGenTableColumnAddParamModel paramModel) {

    }

    @Transactional(rollbackFor = Exception.class)
    public void edit(AppGenTableColumnEditParamModel paramModel) {

    }

    @Transactional(rollbackFor = Exception.class)
    public void del(String id) {
        removeById(id);
    }

    @Transactional(rollbackFor = Exception.class)
    public void dels(String[] ids) {
        for (String id : ids) {
            removeById(id);
        }
    }

    public List<AppGenTableColumnEntity> findAllByGenTableId(String genTableId) {
        return list(Wrappers.<AppGenTableColumnEntity>query().eq("gen_table_id",genTableId).orderByAsc("sort"));
    }

    public List<AppGenTableColumnEntity> selectDbTableColumnsByName(String tableName) {
        return baseMapper.selectDbTableColumnsByName(tableName);
    }
}